#include <iostream>

using namespace std;

class Solution {
public:
    int mySqrt(int x) {
        /*
        if(x==0){
            return 0;
        }
        int i=1;
        int last=1;
        while(true){
            if(i<=x/i){
                if((i+1)>x/(i+1)){
                    return i;
                }
                last=i;
                i=2*i;
            } else{
                i=(i+last)/2;
            }
            cout<<"i:"<<i<<",last:"<<last<<endl;
        }
        return i;
        */
        if(x<2){
            return x;
        }
        int left=1;
        int right=x-1;
        int mid=0;
        while(true){
            mid=left+(right-left)/2;
            if(mid==x/mid||(mid<=x/mid&&(mid+1)>x/(mid+1))){
                //return mid;
                break;
            } else{
                if(mid<x/mid){
                    left=mid;
                } else{
                    right=mid;
                }
            }
            //cout<<"left:"<<left<<",mid:"<<mid<<",right:"<<right<<endl;
        }
        return mid;
    }
};

int main(){
    Solution s;
    int in=80;
    cout<<s.mySqrt(in)<<endl;
}